% FWEAVE v1.30 (May 15, 1993)

\input fwebmac.sty

\Wbegin[]{article}{1em}{1em}{f90_cpp.cts}{{\&}{\|}{\\}{\\}{\\}{\@}{\.}{\.}}


% --- Overloaded operator definitions from @v for 'C++' ---
\newbinop{STAR}{C++}{\times}

% --- Overloaded operator definitions from @v for 'R90' ---
\newbinop{LE}{R90}{\subset} \newop{MOD}{R90}{.} \newbinop{LE}{R90}{\subset} %
\newbinop{IN}{R90}{\in}

% --- Limbo text from @l ---
\let\WARRAY\WSUB

% --- Beginning of user's limbo section ---




\WN1.  INTRODUCTION.  This example demonstrates operator overloading in both
Ratfor--90 and~C$++$.  It also shows how brackets may be used instead of
parentheses for \Fortran\ array indices.
\WY $\WP\Wl::\.{"\\\\let\\\\WARRAY\\\\WSUB"}{}$\5
\Wc{ Subscript \Fortran\ indices.}\par
\WY\WP \WX2:Ratfor--90\X \X\LANGUAGE{C++}\6
\WX5:C$++$\X C++\X\WY\par
\fi % End of module 1

\WM2. The following example is excerpted from the ANSI Draft~S8, Version~112
for the Fortran--90 language.

\WY $\WP\Wv::\.{.IN.}{}$ ${}\.{"\\\\in"}{}$ ${}{<}{}$\5
\WC{ Make \.{.IN.} display as~`$\in$' and be treated as a relational operator.
}\par
 $\WP\Wv::{\WL}{}$ ${}\.{"\\\\subset"}{}$ ${}{\WL}{}$\5
\WC{ Make \.{.LE.} display as~`$\subset$' and be treated as a relational
operator. }\WY\par
\WY\WP\4\4\WX2:Ratfor--90\X \X${}\WS{}$\7
\&{module} \1\\{integer\_sets}\WIN1{0}\2\1\6
${}\{$\6
\&{integer}, \&{parameter}${}\CF$\1${}\\{max\_set\_card}=\WO{200};$\2\7
\&{type} \\{set}\1\6
${}\{$\6
\4\&{private}:\6
\&{integer} \1\\{card};\2\6
\&{integer} \1\\{element}${}\WXA{\\{max\_set\_card}};$\2\6
${}\}$\2\1;\2\7
\&{interface} \&{operator} (${\optrue\Wb{IN}{R90}\opfalse})$\1\6
${}\{$\6
\&{module} \&{procedure} \1\\{element};\2\6
${}\}$\2\1;\2\7
\&{interface} \&{operator} (${\optrue\Wb{LE}{R90}\opfalse})$\1\6
${}\{$\6
\&{module} \&{procedure} \1\\{subset};\2\6
${}\}$\2\1;\2\7
\WX3:Union function\X \X\6
\WX4:Subset function\X \X\6
${}\}$\2\WY\par
\WU section~1.\fi % End of module 2

\WM3. This function uses structure elements.  We overload the element
operator~`\.{\%}' to make the resulting code look more like~\C.

\WY $\WP\Wv::{\MOD}{}$ ${}\.{"."}$ $.{}$\5
\Wc{ Make \.\% print as~`\..' and also be treated as~`\..'.}\WY\par
\WY\WP\4\4\WX3:Union function\X \X${}\WS{}$\7
\&{function} \1\\{union}\WIN1{0}(\|A,\39\|B)\2\1\1\6
${}\&{type}\,(\\{set})$ \1\|A, \|B;\2\2\2\1\6
${}\{$\6
${}\&{type}\,(\\{set})$ \1\\{UNION};\2\6
\&{integer} \1\|j;\2\7
${}\\{UNION}=\|A;$\6
\&{do} ${}\|j=\WO{1},\39\|B \Wop{MOD}{R90}\\{card};$\1\6
${}\&{if}\,(\WR(\|B \Wop{MOD}{R90}\\{element}\WXA{\|j}\Wb{IN}{R90}\|A))$\1\6
${}\&{if}\,(\\{UNION} \Wop{MOD}{R90}\\{card}<\\{max\_set\_card})$\1\6
${}\{$\6
${}\\{UNION} \Wop{MOD}{R90}\\{card}\Wcp\WO{1};$\6
${}\\{UNION} \Wop{MOD}{R90}\\{element}\WXA{\\{UNION} \Wop{MOD}{R90}\\{card}}=%
\|B \Wop{MOD}{R90}\\{element}\WXA{\|j};$\6
${}\}$\2\6
\&{else}  ;\5
\Wc{ Maximum set size exceeded...}\2\2\6
${}\}$\2\WY\par
\WU section~2.\fi % End of module 3

\WM4. We claim that this is much more visually appealing than a raw listing.
\WY\WP\4\4\WX4:Subset function\X \X${}\WS{}$\7
\&{logical} \&{function} \1\\{subset}\WIN1{0}(\|A,\39\|B)\2\1\1\6
${}\&{type}\,(\\{set})$ \1\|A, \|B;\2\2\2\1\6
${}\{$\6
\&{integer} \1\|i;\2\7
${}\\{subset}\WIN1{0}=\|A \Wop{MOD}{R90}\\{card}\Wb{LE}{R90}\|B \Wop{MOD}{R90}%
\\{card};{}$\5
\WC{ In the source, this is ``\.{subset\ =\ A\%card\ <=\ B\%card;}'' }\6
${}\&{if}\,(\WR\\{subset}\WIN1{0})$ \&{return};\7
\&{do} ${}\|i=\WO{1},\39\|A \Wop{MOD}{R90}\\{card};$\1\6
${}\\{subset}\WIN1{0}=\\{subset}\WIN1{0}\WW(\|A \Wop{MOD}{R90}\\{element}\WXA{%
\|i}\Wb{IN}{R90}\|B);$\2\6
${}\}$\2\WY\par
\WU section~2.\fi % End of module 4

\WM5. Here is a short example of operator overloading in~\Cpp.  Note that since
the
global language is \Ratfor--90, we must explicitly insert a language
command in the following definition section in order that the star be
overloaded in the proper language.
\WY $\WP\Wv:C++:{\ast}{}$ ${}\.{"\\\\times"}{}$ ${}{\ast}{}$\par
\WY\WP\4\4\WX5:C$++$\X C++\X${}\WS{}$\7
\&{class} \&{complex}\1\6
${}\{$\6
\&{double} \1\\{re}, \\{im};\2\7
\4\&{public}:\6
${}\&{complex}\,{}$(\&{double} \1\|r,$\,{}$\&{double} \|i)\2\1\6
${}\{$\6
${}\\{re}=\|r;{}$\ ${}\\{im}=\|i;$\6
${}\}$\2\6
\&{friend} \&{complex} \1\&{operator} ${+}(\&{complex},\,\&{complex})$\2;\6
\&{friend} \&{complex} \1\&{operator} ${\Wb{STAR}{C++}}(\&{complex},\,%
\&{complex})$\2;\6
${}\}$\2\1;\2\7
${}\|z=\|x\Wb{STAR}{C++}\|y;{}$\5
\WC{ An example of a statement using the overloading multiplication operator. }%
\WY\par
\WU section~1.\fi % End of module 5

\WN6.  INDEX.
\fi % End of module 6

\input f90_cpp.ndx
\input f90_cpp.mds

\Winfo{"fweave ./f90\_cpp -zdemos.sty -=f90\_cpp.tex"}  {"./f90\_cpp.web"}
{(none)}
 {RATFOR--90}

\Wcon
